home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / perl5 / DateTimePPExtra.pm < prev    next >
Encoding:
Perl POD Document  |  2010-07-30  |  1.4 KB  |  70 lines

  1. package DateTime;
  2. BEGIN {
  3.   $DateTime::VERSION = '0.61';
  4. }
  5.  
  6. use strict;
  7. use warnings;
  8.  
  9. use DateTime::LeapSecond;
  10.  
  11. sub _normalize_tai_seconds {
  12.     return if grep { $_ == INFINITY() || $_ == NEG_INFINITY() } @_[ 1, 2 ];
  13.  
  14.     # This must be after checking for infinity, because it breaks in
  15.     # presence of use integer !
  16.     use integer;
  17.  
  18.     my $adj;
  19.  
  20.     if ( $_[2] < 0 ) {
  21.         $adj = ( $_[2] - 86399 ) / 86400;
  22.     }
  23.     else {
  24.         $adj = $_[2] / 86400;
  25.     }
  26.  
  27.     $_[1] += $adj;
  28.  
  29.     $_[2] -= $adj * 86400;
  30. }
  31.  
  32. sub _normalize_leap_seconds {
  33.  
  34.     # args: 0 => days, 1 => seconds
  35.     my $delta_days;
  36.  
  37.     use integer;
  38.  
  39.     # rough adjust - can adjust many days
  40.     if ( $_[2] < 0 ) {
  41.         $delta_days = ( $_[2] - 86399 ) / 86400;
  42.     }
  43.     else {
  44.         $delta_days = $_[2] / 86400;
  45.     }
  46.  
  47.     my $new_day = $_[1] + $delta_days;
  48.     my $delta_seconds
  49.         = ( 86400 * $delta_days )
  50.         + DateTime::LeapSecond::leap_seconds($new_day)
  51.         - DateTime::LeapSecond::leap_seconds( $_[1] );
  52.  
  53.     $_[2] -= $delta_seconds;
  54.     $_[1] = $new_day;
  55.  
  56.     # fine adjust - up to 1 day
  57.     my $day_length = DateTime::LeapSecond::day_length($new_day);
  58.     if ( $_[2] >= $day_length ) {
  59.         $_[2] -= $day_length;
  60.         $_[1]++;
  61.     }
  62.     elsif ( $_[2] < 0 ) {
  63.         $day_length = DateTime::LeapSecond::day_length( $new_day - 1 );
  64.         $_[2] += $day_length;
  65.         $_[1]--;
  66.     }
  67. }
  68.  
  69. 1;
  70.